package com.luojing.myThread.blockingqueue.arrayblockingqueue;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

/**
 * 顺序队列,顺序存取
 * @author luojing
 * @create 2018/09/01 下午1:30
 **/
public class ArrayBlockingQueueDemo {

  public static void main(String[] args) throws InterruptedException {
    final BlockingQueue<String> blockingDeque = new ArrayBlockingQueue<String>(16,true);

    for(int i = 0; i < 16;i++){
      String data = i + "";

      blockingDeque.put(data);
      System.out.println("put:" + data);
    }
    for(int i = 0;i < 4;i++){
      new Thread(new Runnable() {
        @Override
        public void run() {
          try {
            while (true){
              String data = blockingDeque.take();
              Thread.sleep(2000L);//处理数据
              System.out.println(data);
            }
          } catch (InterruptedException e) {
            e.printStackTrace();
          }
        }
      }).start();
    }

  }

}
